package com.xqx.controller;

import com.xqx.domain.Account;
import com.xqx.domain.ResultInfo;
import com.xqx.service.AccountService;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author：xingquanxiang createTime：2019/10/7 9:38
 * description:
 */
@Controller
@RequestMapping("/account")
public class AccountController {
    @Autowired
    private AccountService accountService;

    @RequestMapping("/list.do")
    @ResponseBody
    public ResultInfo list() {
        List<Account> accountList = accountService.findAll();
        accountList.forEach(account -> System.out.println(account));
        ResultInfo resultInfo = new ResultInfo();
        if (accountList.size() > 0) {
            resultInfo.setFlag(true);
            resultInfo.setData(accountList);
        }
        return resultInfo;
    }

    @RequestMapping("/save.do")
    public String save(String name, double money) {
        Account account = new Account();
        account.setName(name);
        account.setMoney(money);
        accountService.save(account);
        return "redirect:/index.html";
    }
}
